package io.renren.modules.store.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.annotation.NoRepeatSubmit;
import io.renren.common.utils.ReplaceUtil;
import io.renren.modules.sys.controller.AbstractController;
import net.sf.jsqlparser.statement.replace.Replace;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.store.entity.TStoreServiceConstEntity;
import io.renren.modules.store.service.TStoreServiceConstService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author steakliu
 * @email 2319492349@qq.com
 * @date 2021-03-18 23:26:12
 */
@RestController
@RequestMapping("store/tstoreserviceconst")
public class TStoreServiceConstController extends AbstractController {
    @Autowired
    private TStoreServiceConstService tStoreServiceConstService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("store:tstoreserviceconst:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = tStoreServiceConstService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info")
    //@RequiresPermissions("store:tstoreserviceconst:info")
    public R info(){
		TStoreServiceConstEntity tStoreServiceConst = tStoreServiceConstService.getOne(new QueryWrapper<TStoreServiceConstEntity>()
            .eq("seller_id",getSeller())
        );
		tStoreServiceConst.setFoodsList(ReplaceUtil.strToList(tStoreServiceConst.getFoods()));
		tStoreServiceConst.setBusinessTimeList(ReplaceUtil.strToList(tStoreServiceConst.getBusinessTime()));
		tStoreServiceConst.setDeskAreaList(ReplaceUtil.strToList(tStoreServiceConst.getDeskArea()));
        tStoreServiceConst.setRegionList(ReplaceUtil.strToList(tStoreServiceConst.getRegions()));
        return R.ok().put("tStoreServiceConst", tStoreServiceConst);
    }

    /**
     * 保存
     */
    @NoRepeatSubmit
    @RequestMapping("/save")
    //@RequiresPermissions("store:tstoreserviceconst:save")
    public R save(@RequestBody TStoreServiceConstEntity tStoreServiceConst){
        tStoreServiceConst.setSellerId(getSeller());
        tStoreServiceConst.setCreateTime(new Date());
        tStoreServiceConst.setDeskArea(ReplaceUtil.replaceZKH(tStoreServiceConst.getDeskAreaList().toString()));
        tStoreServiceConst.setBusinessTime(ReplaceUtil.replaceZKH(tStoreServiceConst.getBusinessTimeList().toString()));
        tStoreServiceConst.setFoods(ReplaceUtil.replaceZKH(tStoreServiceConst.getFoodsList().toString()));
        tStoreServiceConst.setRegions(ReplaceUtil.replaceZKH(tStoreServiceConst.getRegionList().toString()));
		tStoreServiceConstService.saveOrUpdate(tStoreServiceConst);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("store:tstoreserviceconst:update")
    public R update(@RequestBody TStoreServiceConstEntity tStoreServiceConst){
		tStoreServiceConstService.updateById(tStoreServiceConst);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("store:tstoreserviceconst:delete")
    public R delete(@RequestBody Long[] ids){
		tStoreServiceConstService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
